package edu.hawaii.ics414;

import java.util.HashMap;
import java.util.Map;
import android.os.AsyncTask;

/**
 * Gets the current list of games listed in the database.
 * 
 * @author Matthew Mizumoto
 * 
 */

public class GetGameList extends AsyncTask<String, Void, String[]> {

  @Override
  /*
   * Required by the AsyncTask class. Sends data to the appropriate php page for updates/queries
   * (non-Javadoc)
   * 
   * @params params A variable amount of Strings to send as form data.
   * 
   * @see android.os.AsyncTask#doInBackground(Params[])
   */
  protected String[] doInBackground(String... params) {
    String listType = (params.length > 0) ? params[0] : "";

    Map<String, String> requestParams = new HashMap<String, String>();
    requestParams.put("list", listType);
    String response =
        Ajax.send("http://ratethatgame.web44.net/ics414/getGameList.php", requestParams);
    if (response != null) {
      String[] gameList = response.split(",");
      return gameList;
    }
    return null;
  }
}
